package day1_array.leetcode;

import java.util.Arrays;

/**
 * 双指针移动0
 * @author yuisama
 * @date 2022/04/19 15:19
 **/
public class Num283_MoveZero {
    public void moveZeroes(int[] nums) {
        int fir = 0,sec = 0;
        // nums[0...fir - 1]都是非0元素
        // nums[fir...n - 1]都是0
        while (sec < nums.length) {
            if (nums[sec] != 0) {
               nums[fir] = nums[sec];
               fir ++;
            }
            sec ++;
        }
        Arrays.fill(nums,fir,nums.length,0);
    }
}